package com.zx.idc.backend.gui.api.ftp;

import com.zx.idc.common.constants.FTPThreadPoolConstant;
import com.zx.idc.common.spring.SpringConfigUtil;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * ftp线程池单例实现
 */
public class FTPThreadPoolFactory {
    private FTPThreadPoolFactory() {

    }

    /**
     * 获取单例的ftp单线程线程池
     *
     * @return
     */
    public static ExecutorService getSingleThreadExecutor() {
        return FTPThreadPoolHolder.singleThreadExecutor;
    }

    /**
     * 获取单例的ftp固定线程线程池
     * 需要修改核心处理线程数 请修改 配置的 ftp.report.thread-pool.corePoolSize
     *
     * @return
     */
    public static ExecutorService getFixedThreadExecutor() {
        return FTPThreadPoolHolder.fixedThreadExecutor;
    }


    private static class FTPThreadPoolHolder {
        private static final ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
        private static final ExecutorService fixedThreadExecutor = Executors.newFixedThreadPool(
            SpringConfigUtil.getInteger(FTPThreadPoolConstant.FTP_THREAD_POOL_CORE_POOL_SIZE)
        );
    }
}
